<?php

namespace App\Librarys;

use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Auth;

class Message{
    
    /**
     * 返回前台带数据JSON消息
     *
     * @param boolean $success
     * @param string $message
     * @param mixed $data
     * @param integer $status
     * @param array $headers
     * @param integer $options
     * @return JsonResponse
     */
    public static function show(bool $success = false, string $message = '返回无意义空消息', mixed $data = [], int $status = 200, array $headers = [], int $options = 0): JsonResponse
    {
        return response()->json(['success' => $success, 'message' => $message, 'data' => $data], $status, $headers, $options);
    }

    /**
     * 返回TOKEN信息
     *
     * @param boolean $success
     * @param string $message
     * @param string $token
     * @return JsonResponse
     */
    public static function token(bool $success = false, string $message = 'token获取失败', string $token = ''): JsonResponse
    {
        return response()->json(['success' => $success, 'message' => $message, 'token' => [
            'access_token' => $token,
            'token_type' => 'bearer',
            'expires_in' => Auth::guard('api')->factory()->getTTL() * 60
        ]]);
    }
}